
import time
import datetime

def change_name(func):
    def wrap(wrapper):
        wrapper.__name__ = func.__name__
        wrapper.__doc__ = func.__doc__
        return wrapper
    return wrap

def timeit(func):
    @change_name(func)               # wrapper = change_name(func)(wrapper)
    def wrapper(*arg, **kwargs):
        '''wrapper-function'''
        stime = datetime.datetime.now()
        ret = func(*arg, **kwargs)
        time = (datetime.datetime.now() - stime).total_seconds()
        print('{}函数运行时间为{}s'.format(func.__name__,time))
        return ret
    return wrapper

@timeit          # func = timeit(func)
def func():
    '''func-function'''
    time.sleep(3)

# 测试
func()
print(func.__name__, func.__doc__)


